/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package at.alexanderpehm.ahnentafel.ui;

import at.alexanderpehm.ahnentafel.persistence.Person;
import java.util.List;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author Alexander Pehm
 */
public class PersonChildFactory extends ChildFactory<Person> {

    private List<Person> resultList;

    public PersonChildFactory(List<Person> resultList) {
        this.resultList = resultList;
    }

    @Override
    protected boolean createKeys(List<Person> list) {
        for (Person person : resultList) {
            list.add(person);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(Person person) {
        Node node = new AbstractNode(Children.LEAF, Lookups.singleton(person));
        node.setDisplayName(person.getGivenName());
        node.setShortDescription(person.getLastName());
        return node;
//        try {
//            return new BeanNode(c);
//        } catch (IntrospectionException ex) {
//            Exceptions.printStackTrace(ex);
//            return null;
//        }
    }
}
